
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>dubbo服务两种方式打包部署到阿里云 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="之前写过dubbo框架的使用方式，但都是停留在开发者角度把框架使用到应用中并且能够 本地运行，但是我们编码的最终目的不是为了自己学习，而是学以致用，学有所用，今天我们 就掰一下如何把dubbo服务部署到自己的阿里云服务器上。">
<meta property="og:type" content="article">
<meta property="og:title" content="dubbo服务两种方式打包部署到阿里云">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2018/07/14/dubbo服务两种方式打包部署到阿里云/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="之前写过dubbo框架的使用方式，但都是停留在开发者角度把框架使用到应用中并且能够 本地运行，但是我们编码的最终目的不是为了自己学习，而是学以致用，学有所用，今天我们 就掰一下如何把dubbo服务部署到自己的阿里云服务器上。">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar3.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar10.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar4.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar6.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar7.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar8.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar9.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar11.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar12.png">
<meta property="og:updated_time" content="2018-07-15T02:46:14.259Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="dubbo服务两种方式打包部署到阿里云">
<meta name="twitter:description" content="之前写过dubbo框架的使用方式，但都是停留在开发者角度把框架使用到应用中并且能够 本地运行，但是我们编码的最终目的不是为了自己学习，而是学以致用，学有所用，今天我们 就掰一下如何把dubbo服务部署到自己的阿里云服务器上。">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar1.png">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/" title="dubbo服务两种方式打包部署到阿里云" itemprop="url">dubbo服务两种方式打包部署到阿里云</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2018-07-14T03:12:42.000Z" itemprop="datePublished"> Published 2018-07-14</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、打成jar包并运行"><span class="toc-number">1.</span> <span class="toc-text">一、打成jar包并运行</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、打成tar-gz包并部署"><span class="toc-number">2.</span> <span class="toc-text">二、打成tar.gz包并部署</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#总结"><span class="toc-number">2.1.</span> <span class="toc-text">总结</span></a></li></ol></li></ol>
		
		</div>
		
		<pre><code>之前写过dubbo框架的使用方式，但都是停留在开发者角度把框架使用到应用中并且能够
本地运行，但是我们编码的最终目的不是为了自己学习，而是学以致用，学有所用，今天我们
就掰一下如何把dubbo服务部署到自己的阿里云服务器上。
</code></pre><a id="more"></a>
<pre><code>对于项目结构不在赘述，此处复用之前几篇文章的代码，具体参考：
</code></pre><blockquote><footer><strong>徒手搭建dubbo</strong><cite><a href="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/%E5%BE%92%E6%89%8B%E6%90%AD%E5%BB%BAdubbo%E6%9C%8D%E5%8A%A1/">scorpioaeolus.oschina.io/typhoon/2017/12/21/%E5%BE%92%E6%89%8B%E6%90%AD%E5%BB%BAdubbo%E6%9C%8D%E5%8A%A1</a></cite></footer></blockquote>
<pre><code>代码路径：git@gitee.com:ScorpioAeolus/dubbo-server.git
我们都知道，阿里云服务器用的是centos，底层也是linux，那么我们想把dubbo服务放到centos上运行至少具备以下几个条件：
 1）具备jvm环境
 2）dubbo注册中心zookeeper
 3）dubbo服务启动关闭需要使用jar命令或者shell脚本
 4）需要把dubbo程序上传到阿里云

阿里云上已经安装了java运行环境和zookeeper，我们需要关心的是如何把本地开发的dubbo服务
 打包成阿里云服务器上可以运行的包。常用的有两种方式，分别是jar命令运行的jar包和使用shell
 脚本启动的tar.gz压缩包，接下来我们将逐一描述。
</code></pre><h5 id="一、打成jar包并运行"><a href="#一、打成jar包并运行" class="headerlink" title="一、打成jar包并运行"></a>一、打成jar包并运行</h5><pre><code>I 在dubbo-server-provider的pom文件中添加一下内容
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div></pre></td><td class="code"><pre><div class="line">&lt;build&gt;</div><div class="line">       &lt;finalName&gt;dubbo-server-provider&lt;/finalName&gt;</div><div class="line">       &lt;!-- 打包资源位置 --&gt;</div><div class="line">       &lt;resources&gt;</div><div class="line">           &lt;resource&gt;</div><div class="line">               &lt;targetPath&gt;$&#123;project.build.directory&#125;/classes&lt;/targetPath&gt;</div><div class="line">               &lt;directory&gt;src/main/resources&lt;/directory&gt;</div><div class="line">               &lt;filtering&gt;true&lt;/filtering&gt;</div><div class="line">               &lt;includes&gt;</div><div class="line">                   &lt;include&gt;**/*.xml&lt;/include&gt;</div><div class="line">                   &lt;include&gt;**/*.properties&lt;/include&gt;</div><div class="line">               &lt;/includes&gt;</div><div class="line">           &lt;/resource&gt;</div><div class="line">           &lt;!-- 结合com.alibaba.dubbo.container.Main --&gt;</div><div class="line">           &lt;resource&gt;</div><div class="line">               &lt;targetPath&gt;$&#123;project.build.directory&#125;/classes/META-INF/spring&lt;/targetPath&gt;</div><div class="line">               &lt;directory&gt;src/main/resources/spring&lt;/directory&gt;</div><div class="line">               &lt;filtering&gt;true&lt;/filtering&gt;</div><div class="line">               &lt;includes&gt;</div><div class="line">                   &lt;include&gt;spring-*.xml&lt;/include&gt;</div><div class="line">               &lt;/includes&gt;</div><div class="line">           &lt;/resource&gt;</div><div class="line">       &lt;/resources&gt;</div><div class="line"></div><div class="line">       &lt;plugins&gt;</div><div class="line">       &lt;!-- 配置manifest文件，以及服务jar的启动类 --&gt;</div><div class="line">       &lt;plugin&gt;</div><div class="line">           &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;</div><div class="line">           &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;</div><div class="line">           &lt;configuration&gt;</div><div class="line">               &lt;classesDirectory&gt;target/classes/&lt;/classesDirectory&gt;</div><div class="line">               &lt;archive&gt;</div><div class="line">                   &lt;manifest&gt;</div><div class="line">                       &lt;!--执行Jar文件的启动类,使用dubbo自带的启动类 --&gt;</div><div class="line">                       &lt;mainClass&gt;com.alibaba.dubbo.container.Main&lt;/mainClass&gt;</div><div class="line">                       &lt;!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 --&gt;</div><div class="line">                       &lt;useUniqueVersions&gt;false&lt;/useUniqueVersions&gt;</div><div class="line">                       &lt;addClasspath&gt;true&lt;/addClasspath&gt;</div><div class="line">                       &lt;!--将服务依赖的jar文件，放到lib文件夹下 --&gt;</div><div class="line">                       &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;</div><div class="line">                   &lt;/manifest&gt;</div><div class="line">                   &lt;manifestEntries&gt;</div><div class="line">                       &lt;Class-Path&gt;.&lt;/Class-Path&gt;</div><div class="line">                   &lt;/manifestEntries&gt;</div><div class="line">               &lt;/archive&gt;</div><div class="line">           &lt;/configuration&gt;</div><div class="line">       &lt;/plugin&gt;</div><div class="line"></div><div class="line">           &lt;!-- 将运行服务的jar文件，依赖的其它jar文件放在lib文件夹下 --&gt;</div><div class="line">           &lt;plugin&gt;</div><div class="line">               &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;</div><div class="line">               &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;</div><div class="line">               &lt;executions&gt;</div><div class="line">                   &lt;execution&gt;</div><div class="line">                       &lt;id&gt;copy-dependencies&lt;/id&gt;</div><div class="line">                       &lt;phase&gt;package&lt;/phase&gt;</div><div class="line">                       &lt;goals&gt;</div><div class="line">                           &lt;goal&gt;copy-dependencies&lt;/goal&gt;</div><div class="line">                       &lt;/goals&gt;</div><div class="line">                       &lt;configuration&gt;</div><div class="line">                           &lt;type&gt;jar&lt;/type&gt;</div><div class="line">                           &lt;includeTypes&gt;jar&lt;/includeTypes&gt;</div><div class="line">                           &lt;useUniqueVersions&gt;false&lt;/useUniqueVersions&gt;</div><div class="line">                           &lt;outputDirectory&gt;</div><div class="line">                               $&#123;project.build.directory&#125;/lib</div><div class="line">                           &lt;/outputDirectory&gt;</div><div class="line">                       &lt;/configuration&gt;</div><div class="line">                   &lt;/execution&gt;</div><div class="line">               &lt;/executions&gt;</div><div class="line">           &lt;/plugin&gt;</div><div class="line">       &lt;/plugins&gt;</div><div class="line"></div><div class="line">       &lt;pluginManagement&gt;</div><div class="line">           &lt;plugins&gt;</div><div class="line">               &lt;!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引起冲突 --&gt;</div><div class="line">               &lt;plugin&gt;</div><div class="line">                   &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;</div><div class="line">                   &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;</div><div class="line">                   &lt;version&gt;1.0.0&lt;/version&gt;</div><div class="line">                   &lt;configuration&gt;</div><div class="line">                       &lt;lifecycleMappingMetadata&gt;</div><div class="line">                           &lt;pluginExecutions&gt;</div><div class="line">                               &lt;pluginExecution&gt;</div><div class="line">                                   &lt;pluginExecutionFilter&gt;</div><div class="line">                                       &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;</div><div class="line">                                       &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;</div><div class="line">                                       &lt;versionRange&gt;[2.0,)&lt;/versionRange&gt;</div><div class="line">                                       &lt;goals&gt;</div><div class="line">                                           &lt;goal&gt;copy-dependencies&lt;/goal&gt;</div><div class="line">                                       &lt;/goals&gt;</div><div class="line">                                   &lt;/pluginExecutionFilter&gt;</div><div class="line">                                   &lt;action&gt;</div><div class="line">                                       &lt;ignore /&gt;</div><div class="line">                                   &lt;/action&gt;</div><div class="line">                               &lt;/pluginExecution&gt;</div><div class="line">                           &lt;/pluginExecutions&gt;</div><div class="line">                       &lt;/lifecycleMappingMetadata&gt;</div><div class="line">                   &lt;/configuration&gt;</div><div class="line">               &lt;/plugin&gt;</div><div class="line">           &lt;/plugins&gt;</div><div class="line">       &lt;/pluginManagement&gt;</div><div class="line"></div><div class="line">   &lt;/build&gt;</div></pre></td></tr></table></figure>
<pre><code>II 运行package命令打包
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar1.png" alt="dubbo" title="dubbo">
<pre><code>III 使用xshell客户端的rz命令上传jar到云服务器
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar2.png" alt="dubbo" title="dubbo">
<pre><code>IV 启动dubbo服务
使用java -jar dubbo-server-provider.jar &amp;命令运行jar包启动服务
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar3.png" alt="dubbo" title="dubbo">
<pre><code>看到日志打印出了服务启动成功，理论上服务已经启动成功了，看一下java进程是否存在：
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar10.png" alt="dubbo" title="dubbo">
<pre><code>进程已经存在，但是我们要到dubbo控制台看一下有没有注册成功:
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar4.png" alt="dubbo" title="dubbo">
<pre><code>在dubbo-admin控制台看到了服务，也就是说我们的服务已经启动成功并注册到了zookeeper上，理论上已经部署成功了
</code></pre><h5 id="二、打成tar-gz包并部署"><a href="#二、打成tar-gz包并部署" class="headerlink" title="二、打成tar.gz包并部署"></a>二、打成tar.gz包并部署</h5><pre><code>I 在src目录下添加assembly目录并添加assembly.xml文件
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar6.png" alt="dubbo" title="dubbo">
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line">&lt;assembly&gt;</div><div class="line"></div><div class="line">    &lt;id&gt;assembly&lt;/id&gt;</div><div class="line"></div><div class="line">    &lt;formats&gt;</div><div class="line">        &lt;format&gt;tar.gz&lt;/format&gt;</div><div class="line">    &lt;/formats&gt;</div><div class="line"></div><div class="line">    &lt;includeBaseDirectory&gt;true&lt;/includeBaseDirectory&gt;</div><div class="line"></div><div class="line">    &lt;fileSets&gt;</div><div class="line">        &lt;fileSet&gt;</div><div class="line">            &lt;!--&lt;directory&gt;$&#123;project.build.directory&#125;/dubbo/META-INF/assembly/bin&lt;/directory&gt;--&gt;</div><div class="line">            &lt;directory&gt;src/main/resources/scripts&lt;/directory&gt;</div><div class="line">            &lt;outputDirectory&gt;bin&lt;/outputDirectory&gt;</div><div class="line">            &lt;fileMode&gt;0755&lt;/fileMode&gt;</div><div class="line">        &lt;/fileSet&gt;</div><div class="line">        &lt;fileSet&gt;</div><div class="line">            &lt;directory&gt;src/main/resources&lt;/directory&gt;</div><div class="line">            &lt;outputDirectory&gt;conf&lt;/outputDirectory&gt;</div><div class="line">            &lt;includes&gt;</div><div class="line">                &lt;include&gt;server.properties&lt;/include&gt;</div><div class="line">            &lt;/includes&gt;</div><div class="line">            &lt;fileMode&gt;0644&lt;/fileMode&gt;</div><div class="line">        &lt;/fileSet&gt;</div><div class="line">    &lt;/fileSets&gt;</div><div class="line"></div><div class="line">    &lt;dependencySets&gt;</div><div class="line">        &lt;dependencySet&gt;</div><div class="line">            &lt;useProjectArtifact&gt;true&lt;/useProjectArtifact&gt;</div><div class="line">            &lt;outputDirectory&gt;lib&lt;/outputDirectory&gt;</div><div class="line">        &lt;/dependencySet&gt;</div><div class="line">    &lt;/dependencySets&gt;</div><div class="line"></div><div class="line">&lt;/assembly&gt;</div></pre></td></tr></table></figure>
<pre><code>并在dubbo-server-provider的pom文件中添加一下内容：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">&lt;build&gt;</div><div class="line">    &lt;plugins&gt;</div><div class="line">        &lt;plugin&gt;</div><div class="line">            &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;</div><div class="line">            &lt;configuration&gt;</div><div class="line">                &lt;descriptor&gt;src/main/assembly/assembly.xml&lt;/descriptor&gt;</div><div class="line">            &lt;/configuration&gt;</div><div class="line">            &lt;executions&gt;</div><div class="line">                &lt;execution&gt;</div><div class="line">                    &lt;id&gt;make-assembly&lt;/id&gt;</div><div class="line">                    &lt;phase&gt;package&lt;/phase&gt;</div><div class="line">                    &lt;goals&gt;</div><div class="line">                        &lt;goal&gt;single &lt;/goal&gt;</div><div class="line">                    &lt;/goals&gt;</div><div class="line">                &lt;/execution&gt;</div><div class="line">            &lt;/executions&gt;</div><div class="line">        &lt;/plugin&gt;</div><div class="line">    &lt;/plugins&gt;</div><div class="line"> &lt;/build&gt;</div></pre></td></tr></table></figure>
<pre><code>II 运行package命令打包
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar7.png" alt="dubbo" title="dubbo">
<pre><code>在项目的target目录下生成了tar.gz文件

III 使用xshell客户端的rz命令上传jar到云服务器
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar8.png" alt="dubbo" title="dubbo">
<pre><code>IV 运行 tar zxvf dubbo-server-provider-1.0-SNAPSHOT-assembly.tar.gz命令解压
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar9.png" alt="dubbo" title="dubbo">
<pre><code>V 通过脚本启动服务
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sh ./start.sh</div></pre></td></tr></table></figure>
<pre><code>发现报错了：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">-bash: ./start.sh: /bin/bash^M: bad interpreter: No such file or directory</div></pre></td></tr></table></figure>
<pre><code>主要原因是test.sh是我在windows下编辑然后上传到linux系统里执行的。
.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本。
通过vim命令修改format格式：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">:set ff = unix</div></pre></td></tr></table></figure>
<pre><code>然后再运行start.sh，看一下java进程是否存在：
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar11.png" alt="dubbo" title="dubbo">
<pre><code>进程已经存在，看一下dubbo-admin中服务是否注册成功:
</code></pre><img src="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/jar12.png" alt="dubbo" title="dubbo">
<pre><code>在dubbo-admin控制台看到了服务，也就是说我们的服务已经启动成功并注册到了zookeeper上，也就是
我们的服务已经在阿里云上部署成功了。
</code></pre><h6 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h6><pre><code>    对于两种方式各有优缺点，此处做一下简单分析对比：
    I jar包方式
    优点：打包和运行简单
    缺点：启动和中指都要手工操作
    II tar.gz方式
    优点：使用脚本启动，支持自动化运维
    缺点：打包比较复杂
    大部分公司应该使用脚本启动方式部署。经过上述的描述和代码验证，我们已经通过两种常用的方式把
我们在本地开发的dubbo服务打包并成功部署到阿里云服务器上，希望给大家的日常学习和开发中带来帮助。
</code></pre><p><strong><em>PS:原创不易,多多支持!</em></strong></p>
  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/dubbo/">dubbo</a>
</div>


</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2018/07/14/dubbo服务两种方式打包部署到阿里云/" data-title="dubbo服务两种方式打包部署到阿里云 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2018/07/15/聊一聊去if-else方案/" title="聊一聊去if-else方案">
  <strong>上一篇：</strong><br/>
  <span>
  聊一聊去if-else方案</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2018/06/02/dubbo管理平台搭建/"  title="dubbo管理平台搭建">
 <strong>下一篇：</strong><br/> 
 <span>dubbo管理平台搭建
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、打成jar包并运行"><span class="toc-number">1.</span> <span class="toc-text">一、打成jar包并运行</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、打成tar-gz包并部署"><span class="toc-number">2.</span> <span class="toc-text">二、打成tar.gz包并部署</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#总结"><span class="toc-number">2.1.</span> <span class="toc-text">总结</span></a></li></ol></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
